package com.lt.flashcard.view;

import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.util.Clients;

import com.lt.flashcard.Utility;
import com.lt.flashcard.model.entity.User;
import com.lt.flashcard.model.service.Repository;
import com.lt.flashcard.model.service.UserService;
import com.lt.ltmng.converter.ListEntryConverter;

public class PrivacyCtrl {
	
	private User user;
	private ListEntryConverter converter = new ListEntryConverter();

	@Init
	public void init() {
		Utility.requireAuthenticated(false);
		user = Utility.getUser();
	}
	
	@Command
	public void save() {
		UserService usrv = Repository.getInstance().getUserService();
		User cu = Repository.getInstance().getAAService().getCurrentUser();
		cu.setPrivacyCoin(user.getPrivacyCoin());
		cu.setPrivacyCompare(user.getPrivacyCompare());
		cu.setPrivacyFlashcard(user.getPrivacyFlashcard());
		cu.setPrivacyFriend(user.getPrivacyFriend());
		cu.setPrivacyFriendrequest(user.getPrivacyFriendrequest());
		cu.setPrivacyJourney(user.getPrivacyJourney());
		cu.setPrivacyLearning(user.getPrivacyLearning());
		cu.setPrivacyMedal(user.getPrivacyMedal());
		cu.setPrivacyProfile(user.getPrivacyProfile());
		cu.setPrivacySeemyfeed(user.getPrivacySeemyfeed());
		cu.setPrivacySeeotherfeed(user.getPrivacySeeotherfeed());
		cu.setPrivacySendmessage(user.getPrivacySendmessage());
		
		usrv.save(cu);
		
		Clients.evalJavaScript("showNotice('Save successfully')");
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public ListEntryConverter getConverter() {
		return converter;
	}
}
